<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>error(fn)</title>
<meta name="keywords" content="jQuery 1.2 API Reference,Visual jQuery 1.2,jQuery doc,jQuery API,jQuery,jQuery 1.2 API 参考文档中文版,中文版" />
<meta name="description" content="jQuery 1.2 API 文档中文版，提供最新版 jQuery 开发帮助。" />
<link rel="stylesheet" type="text/css" href="../../style/jqueryapi.css" />
<script type="text/javascript" src="../../style/lib/jquery126.js"></script>
 </script>
<script type="text/javascript" src="../../style/jqueryapi.js"></script>
<link rel="shortcut icon" href="../../style/img/favicon.ico" />
</head>
<body>
<div id="topnav">
		<a href="http://www.jQuery.com/" title="jQuery官网" target="_blank" class="topnav">jQuery官网</a>
	<span class="topnav">|</span>
	<a href="http://jquery.org.cn/" title="jQuery中文网站" target="_blank" class="topnav">jQuery中文网站</a>
	<span class="topnav">|</span>
	<a href="http://www.cn-cuckoo.com/" title="1.1版译者" target="_blank" class="topnav">为之漫笔</a>
	<span class="topnav">|</span>
	<a href="http://shawphy.com/" title="1.2版翻译整理者" target="_blank" class="topnav">Shawphy</a>
    <span class="topnav">|</span>
	<a href="http://www.51toria.cn" title="CHM文档制作者:一揪" target="_blank" class="topnav">CHM文档制作者</a> 
	<span class="topnav">|</span>
	<a href="http://dl.getdropbox.com/u/81097/jQueryAPI_CHM.CHM" title="" target="_blank" class="topnav">CHM最新版本下载</a> 
</div>
<hr style="color:#595959;" />

<div class="content">
				<h1>error(fn)</h1>
				<div class="desc"><div>在每一个匹配元素的error事件中绑定一个处理函数。</div> <div class="longdesc"><p>对于error事件，没有一个公众的标准。在大多数浏览器中，当页面的JavaScript发生错误时，window对象会触发error事件;当图像的src属性无效时，比如文件不存在或者图像数据错误时，也会触发图像对象的error事件。</p><p>如果异常是由window对象抛出，事件处理函数将会被传入三个参数：</p><p>1. 描述事件的信息 ("varName is not defined", "missing operator in expression", 等等.),</p><p>2. 包含错误的文档的完整URL</p><p>3. 异常发生的行数</p> <p>如果事件处理函数返回true，则表示事件已经被处理，浏览器将认为没有异常。</p><p>更多相关信息: </p><p><a href="http://msdn2.microsoft.com/en-us/library/ms536930.aspx" >msdn - onerror Event</a></p><p><a href="http://developer.mozilla.org/en/docs/DOM:window.onerror" >Gecko DOM Reference - onerror Event</a></p><p><a href="http://developer.mozilla.org/en/docs/DOM:event">Gecko DOM Reference - Event object</a></p><p><a href="http://en.wikipedia.org/wiki/DOM_Events">Wikipedia: DOM Events</a></p></div></div><hr />
				<div class="desc"><div>Binds a function to the error event of each matched element.</div> <div class="longdesc"><p>There is no public standard for the error event. In most browsers, the window object's error event is triggered when a JavaScript error occurs on the page. An image object's error event is triggered when it is set an invalid src attribute - either a non-existent file, or one with corrupt image data.</p><p>If the event is thrown by the window object, the event handler will be passed three parameters: </p><p>1. A message describing the event ("varName is not defined", "missing operator in expression", etc.),</p><p>2. the full URL of the document containing the error, and</p><p>3. the line number on which the error occured.</p> <p>If the event handler returns true, it signifies that the event was handled, and the browser raises no errors.</p><p>For more information, see: </p><p><a href="http://msdn2.microsoft.com/en-us/library/ms536930.aspx" >msdn - onerror Event</a></p><p><a href="http://developer.mozilla.org/en/docs/DOM:window.onerror" >Gecko DOM Reference - onerror Event</a></p><p><a href="http://developer.mozilla.org/en/docs/DOM:event">Gecko DOM Reference - Event object</a></p><p><a href="http://en.wikipedia.org/wiki/DOM_Events">Wikipedia: DOM Events</a></p></div></div>
				<h2>返回值</h2>
				<p class="indent">jQuery</p>
				<h2>参数</h2>
				<p class="indent"><strong>fn </strong>(Function) :在每一个匹配元素的error事件中绑定的处理函数。</p>
				<h2>示例</h2>
				<p class="indent">
					在服务器端记录JavaScript错误日志: 
				</p>
				<p class="indent"><strong>jQuery 代码:</strong></p>
				<div class="code">
					$(window).error(function(msg, url, line){<br/>
&nbsp; jQuery.post("js_error_log.php", { msg: msg, url: url, line: line });<br/>
});
				</div>
				<hr />
				<p class="indent">
					隐藏JavaScript错误: 
				</p>
				<p class="indent"><strong>jQuery 代码:</strong></p>
				<div class="code">
					$(window).error(function(){<br/>
&nbsp; return true;<br/>
});
				</div>
				<hr />
				<p class="indent">
					给你IE的用户隐藏无效的图像: 
				</p>
				<p class="indent"><strong>jQuery 代码:</strong></p>
				<div class="code">
					$("img").error(function(){<br/>
&nbsp; $(this).hide();<br/>
});
				</div>
			</div>
            
</body>
</html>
